package com.Servlet;

import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jdbc.Jdbc;

/**
 * Servlet implementation class searchrestclasstime
 */
@WebServlet("/searchrestclasstime")
public class searchrestclasstime extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public searchrestclasstime() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		String restclasstime = request.getParameter("restclasstime");
		String username = (String) request.getSession().getAttribute("username");
		String role = (String) request.getSession().getAttribute("role");
		String find = null;

		if (role.equals("管理员")) {
			find = "select contractid,id,chinesename,englishname,sex,coursename,totalclass,restclass from contract where restclass<="
					+ restclasstime;
		} else {
			find = "select contractid,id,chinesename,englishname,sex,coursename,totalclass,restclass from contract where restclass<="
					+ restclasstime+" and username="+username;
		}
		Jdbc j3 = new Jdbc();
		ResultSet rs = null;
		try {
			j3.Jdbc_Q2(find);
			rs = j3.rs;
			request.setAttribute("resultset", rs);
			request.getRequestDispatcher("restclasstime_info.jsp").forward(request, response);
		} catch (ClassNotFoundException | SQLException e) {
			e.printStackTrace();
		}
	}

}
